/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Password_panel.java
 *
 * Created on 22-05-2009, 19:49:35
 */

package VIEW;

import CONTROLLER.Controller;
import java.util.Observable;
import java.util.Observer;
import javax.swing.DefaultListModel;

/**
 *
 * @author Irene
 */
public class Password_panel extends javax.swing.JPanel implements Observer {
private Controller ctrl;
    /** Creates new form Password_panel */
    public Password_panel(Controller ctrl) {
        this.ctrl = ctrl;
        initComponents();
        ctrl.addObserver(this);

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        UserNameField = new javax.swing.JTextField();
        PasswordField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        fitPassList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        VIPPassList = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        OtherPassList = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        topField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        addFitnessPassword = new javax.swing.JButton();
        addVipPassword = new javax.swing.JButton();
        addOtherPassword = new javax.swing.JButton();
        removeFiteness = new javax.swing.JButton();
        removeVIP = new javax.swing.JButton();
        removeOther = new javax.swing.JButton();
        clearbutton = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Your Passwords");

        jLabel2.setText("UserName:");

        jLabel3.setText("Password:");

        fitPassList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(fitPassList);

        VIPPassList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(VIPPassList);

        OtherPassList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(OtherPassList);

        jLabel4.setText("Fitness Passwords");

        jLabel5.setText("V.I.P Passwords");

        jLabel6.setText("Other Passwords");

        jLabel7.setText("Password to:");

        addFitnessPassword.setText("Add to:");
        addFitnessPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addFitnessPasswordActionPerformed(evt);
            }
        });

        addVipPassword.setText("Add to:");
        addVipPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addVipPasswordActionPerformed(evt);
            }
        });

        addOtherPassword.setText("Add to:");
        addOtherPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addOtherPasswordActionPerformed(evt);
            }
        });

        removeFiteness.setText("Delete");
        removeFiteness.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeFitenessActionPerformed(evt);
            }
        });

        removeVIP.setText("Delete");
        removeVIP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeVIPActionPerformed(evt);
            }
        });

        removeOther.setText("Delete");
        removeOther.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeOtherActionPerformed(evt);
            }
        });

        clearbutton.setText("Clear");
        clearbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearbuttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addComponent(removeFiteness)
                .addGap(114, 114, 114)
                .addComponent(removeVIP)
                .addGap(155, 155, 155)
                .addComponent(removeOther)
                .addContainerGap(191, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(53, 53, 53)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(182, 182, 182)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jLabel3)
                                                    .addComponent(jLabel2))
                                                .addGap(16, 16, 16))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel7)
                                                .addGap(18, 18, 18)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(PasswordField)
                                            .addComponent(UserNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                            .addComponent(topField)
                                            .addComponent(addVipPassword)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(76, 76, 76)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(addFitnessPassword)
                                            .addComponent(jLabel4))))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(clearbutton)
                                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(48, 48, 48)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(addOtherPassword)
                                            .addComponent(jLabel6))))
                                .addGap(13, 13, 13)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(145, 145, 145))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(UserNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(clearbutton))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addFitnessPassword)
                    .addComponent(addVipPassword)
                    .addComponent(addOtherPassword))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(removeFiteness)
                    .addComponent(removeVIP)
                    .addComponent(removeOther))
                .addGap(57, 57, 57))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addFitnessPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFitnessPasswordActionPerformed
        ctrl.addFitnessPassword(topField.getText(), UserNameField.getText(), PasswordField.getText());
    }//GEN-LAST:event_addFitnessPasswordActionPerformed

    private void addVipPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addVipPasswordActionPerformed
         ctrl.addVipPassword(topField.getText(), UserNameField.getText(), PasswordField.getText());
    }//GEN-LAST:event_addVipPasswordActionPerformed

    private void addOtherPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOtherPasswordActionPerformed
        ctrl.addOtherPassword(topField.getText(), UserNameField.getText(), PasswordField.getText());
    }//GEN-LAST:event_addOtherPasswordActionPerformed

    private void removeFitenessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFitenessActionPerformed
                String s = (String) fitPassList.getSelectedValue();
        ctrl.removeFittnessP(s);
    }//GEN-LAST:event_removeFitenessActionPerformed

    private void removeVIPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeVIPActionPerformed
          String s = (String) VIPPassList.getSelectedValue();
        ctrl.removeVIPP(s);
    }//GEN-LAST:event_removeVIPActionPerformed

    private void removeOtherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOtherActionPerformed
       String s = (String) OtherPassList.getSelectedValue();
        ctrl.removeOtherP(s);
    }//GEN-LAST:event_removeOtherActionPerformed

    private void clearbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearbuttonActionPerformed
        topField.setText("");
        UserNameField.setText("");
        PasswordField.setText("");
    }//GEN-LAST:event_clearbuttonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList OtherPassList;
    private javax.swing.JTextField PasswordField;
    private javax.swing.JTextField UserNameField;
    private javax.swing.JList VIPPassList;
    private javax.swing.JButton addFitnessPassword;
    private javax.swing.JButton addOtherPassword;
    private javax.swing.JButton addVipPassword;
    private javax.swing.JButton clearbutton;
    private javax.swing.JList fitPassList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton removeFiteness;
    private javax.swing.JButton removeOther;
    private javax.swing.JButton removeVIP;
    private javax.swing.JTextField topField;
    // End of variables declaration//GEN-END:variables


 public void update(Observable o, Object arg) {
        updatePasswords();
        System.out.println("password virker");
    }

    public void updatePasswords() {
        DefaultListModel list = ctrl.getFitnessList();
        fitPassList.setModel(list);
        DefaultListModel nlist = ctrl.getVipList();
        VIPPassList.setModel(nlist);
        DefaultListModel wlist = ctrl.getMiscList();
        OtherPassList.setModel(wlist);

        repaint();

    }

}
